package com.zhongyouyun.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongyouyun.admin.model.DisplayMainModel;
import com.zhongyouyun.other.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zhongyouyun.admin.service.DisplayMainService;

import java.util.List;


/**
 * @Author: shenyi
 * @Date: 2022-12-09
 * @Description:
 */
@RestController
@RequestMapping("/admin/z_display_main")
@Api(value = "模块主表", tags = {"模块主表"})
public class DisplayMainController {
    @Autowired
    private DisplayMainService service;

    @PostMapping("/selectList")
    @ResponseBody
    @ApiOperation(value = "查询主表数据", notes = "查询主表数据")
    public Result<List<DisplayMainModel>> selectList() {
        List<DisplayMainModel> list = service.selectList(new QueryWrapper<>());
        if (list.size() > 0) {
            return Result.<List<DisplayMainModel>>builder().message("成功").status(0).data(list).build();
        } else {
            return Result.<List<DisplayMainModel>>builder().message("没有任何权限").status(1).build();
        }
    }

    @PostMapping("/updateById")
    @ResponseBody
    @ApiOperation(value = "修改主表数据", notes = "修改主表数据")
    public Result updateById(@RequestBody DisplayMainModel displayMainModel) {
        Boolean flag = service.saveOrUpdate(displayMainModel);
        if (flag) {
            return Result.builder().message("成功").status(0).build();
        } else {
            return Result.builder().message("成功").status(1).build();
        }
    }
}
